using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace DataHelper.BLL
{
    public class Comments
    {
        public int ID { get; set; }
        public int NewsID { get; set; }
        public int LangID { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
        public string Comment { get; set; }
        public DateTime CreatedDate { get; set; }
        public bool IsRead { get; set; }
        public bool IsDeleted { get; set; }

        #region CommentSelectAll
        public static List<Comments> CommentSelectAll(string strSearch="",int top = 1, int bottom = 20, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.Comment.CommentSelectAll(strSearch,top,bottom,ConnectionString);
            List<Comments> CommentList = new List<Comments>();
            while(dr.Read())
            {
                Comments myComment = new Comments
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    NewsID = !dr.IsDBNull(dr.GetOrdinal("NewsID")) ? (int)dr["NewsID"] : 0,
                    LangID = !dr.IsDBNull(dr.GetOrdinal("LangID")) ? (int)dr["LangID"] : 0,
                    Name = !dr.IsDBNull(dr.GetOrdinal("Name")) ? (string)dr["Name"] : null,
                    Email = !dr.IsDBNull(dr.GetOrdinal("Email")) ? (string)dr["Email"] : null,
                    Phone = !dr.IsDBNull(dr.GetOrdinal("Phone")) ? (string)dr["Phone"] : null,
                    Address = !dr.IsDBNull(dr.GetOrdinal("Address")) ? (string)dr["Address"] : null,
                    Comment = !dr.IsDBNull(dr.GetOrdinal("Comment")) ? (string)dr["Comment"] : null,
                    CreatedDate = !dr.IsDBNull(dr.GetOrdinal("CreatedDate")) ? (DateTime)dr["CreatedDate"] : DateTime.Now,
                    IsRead = !dr.IsDBNull(dr.GetOrdinal("IsRead")) ? (bool)dr["IsRead"] : false,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false
                };
                CommentList.Add(myComment);
        }
        dr.Close();
        dr.Dispose();
        return CommentList;
        }
        #endregion
        #region CommentSelectRow
        public static Comments CommentSelectRow(int ID, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.Comment.CommentSelectRow(ID, ConnectionString);
            Comments comment = null;

            if(dr.Read())
            {
                comment= new Comments
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    NewsID = !dr.IsDBNull(dr.GetOrdinal("NewsID")) ? (int)dr["NewsID"] : 0,
                    LangID = !dr.IsDBNull(dr.GetOrdinal("LangID")) ? (int)dr["LangID"] : 0,
                    Name = !dr.IsDBNull(dr.GetOrdinal("Name")) ? (string)dr["Name"] : null,
                    Email = !dr.IsDBNull(dr.GetOrdinal("Email")) ? (string)dr["Email"] : null,
                    Phone = !dr.IsDBNull(dr.GetOrdinal("Phone")) ? (string)dr["Phone"] : null,
                    Address = !dr.IsDBNull(dr.GetOrdinal("Address")) ? (string)dr["Address"] : null,
                    Comment = !dr.IsDBNull(dr.GetOrdinal("Comment")) ? (string)dr["Comment"] : null,
                    CreatedDate = !dr.IsDBNull(dr.GetOrdinal("CreatedDate")) ? (DateTime)dr["CreatedDate"] : DateTime.Now,
                    IsRead = !dr.IsDBNull(dr.GetOrdinal("IsRead")) ? (bool)dr["IsRead"] : false,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false,

                };
            }
        dr.Close();
        dr.Dispose();
        return comment;
        }
        #endregion
        #region CommentInsertRow
        public static void CommentInsertRow(int NewsID, int LangID, string Name, string Email, string Phone, string Address, string Comment, DateTime CreatedDate, bool IsRead, bool IsDeleted, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Comment.CommentInsertRow(NewsID, LangID, Name, Email, Phone, Address, Comment, CreatedDate, IsRead, IsDeleted, ConnectionString);
        }
        #endregion
        #region CommentUpdateRow
        public static void CommentUpdateRow(int ID, int NewsID, int LangID, string Name, string Email, string Phone, string Address, string Comment, DateTime CreatedDate, bool IsRead, bool IsDeleted, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Comment.CommentUpdateRow(ID, NewsID, LangID, Name, Email, Phone, Address, Comment, CreatedDate, IsRead, IsDeleted, ConnectionString);
        }
        #endregion
        #region CommentDeleteRow
        public static void CommentDeleteRow(int ID, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.Comment.CommentDeleteRow(ID,ConnectionString);
        }
        #endregion
    }
}
